#include <iostream>
#include <vector>
using namespace std;
#define int long long

// 这里判断负数复杂，最好是判断是不是超了数量限制
const int N = 1000010;
struct tip {
    tip(int a = 0, int b = 0, int c = 0): x(a), y(b), z(c) {}
    int x = 0, y = 0, z = 0;
};
vector<int> a(N);
vector<tip> c;
int n, m;
bool check(int x) {
    vector<int> b(n + 2, 0);
    for(int i = 1; i <= n; i++) {
        b[i] = a[i] - a[i - 1];
    }
    for(int i = 1; i <= x; i++) {
        b[c[i].y] -= c[i].x;
        b[c[i].z + 1] += c[i].x; 
    }
    int temp = 0;
    for(int i = 1; i <= n; i++) {
        temp += b[i];
        if(temp < 0) {
            return false;
        }
    }
    return true;
}
signed main() {
    
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        int temp;
        cin >> temp;
        a[i] = temp;
    }
    c.push_back(tip(0, 0, 0));
    for(int i = 1; i <= m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        tip t(x, y, z);
        c.push_back(t);
    }
    int left = 1, right = m, ret = -1;
    while(left <= right) {
        int mid = (left + right) >> 1;
        if(check(mid)) {
            left = mid + 1;
        }else {
            ret = mid;
            right = mid - 1;
        }

    }
    if(ret == -1) {
        cout << 0 << endl;
    }else {
        cout << -1 << endl;
        cout << ret << endl;
    }
    return 0;
}